<?php


namespace app\api\controller;


use app\api\model\UserModel;
use app\api\validate\UserValidate;
use app\BaseController;

class user extends  BaseController
{
    //用户注册
    public function register(){
        //接收
        $data = input('post.');

        //验证
        $validate= new UserValidate();
        $result=$validate->scene('validate')->check($data);
        if(!$result){
            return error($validate->geterror());
        }

        //处理密码
        $randStr = createRandStr();
        $password = md5($data['password'].$randStr);
        $data['salt']=$randStr;
        $data['password']=$password;
        // halt($data);
        //入库
        //模型可以自动维护时间戳
//            $data['create_time']=time();

        if(UserModel::create($data)){
            return success('注册成功');
        }else{
            return error('注册失败');
        }
    }
}